<?php
/*
Plugin Name: Social Web Links
Plugin URI: http://nischalmaniar.info/2009/08/social-web-links-plugin/
Version: 3.2
Author: Nischal Maniar
Author URI: http://www.nischalmaniar.info/
*/

/*  Copyright 2009

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/** Define global variables **/
/*****************************/
$social_web_link_options = array();
$imgdir = dirname( __FILE__ )."/images";
$uploaddir = wp_upload_dir();
$customdir = $uploaddir['basedir'];
$customurl = $uploaddir['baseurl'];
if(is_dir($customdir)) {
    $created = false;
    if(!is_dir($customdir.'/social_web_links_icons'))
        $created = mkdir($customdir.'/social_web_links_icons');
    if($created)
        chmod($customdir.'/social_web_links_icons',0777);
        
    if(!is_dir($customdir.'/social_web_links_icons/16x16'))
        $created = mkdir($customdir.'/social_web_links_icons/16x16');
    if($created)
        chmod($customdir.'/social_web_links_icons/16x16',0777);
        
    if(!is_dir($customdir.'/social_web_links_icons/24x24'))
        $created = mkdir($customdir.'/social_web_links_icons/24x24');
    if($created)
        chmod($customdir.'/social_web_links_icons/24x24',0777);
        
    if(!is_dir($customdir.'/social_web_links_icons/32x32'))
        $created = mkdir($customdir.'/social_web_links_icons/32x32');
    if($created)
        chmod($customdir.'/social_web_links_icons/32x32',0777);
        
    if(!is_dir($customdir.'/social_web_links_icons/48x48'))
        $created = mkdir($customdir.'/social_web_links_icons/48x48');
    if($created)
        chmod($customdir.'/social_web_links_icons/48x48',0777);
}

/** Including the core functions file **/
include("social-web-links-functions.php");
get_social_web_links_settings();

/** Including stylesheet **/
function add_social_web_links_header() {
    echo '<link type="text/css" rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-content/plugins/social-web-links/social-web-links-style.css" />'."\n";    
}
add_action('wp_head','add_social_web_links_header');

/** Adding header files to admin options page **/
function add_social_admin_header() {
    echo '<link type="text/css" rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-content/plugins/social-web-links/social-web-links-admin-style.css" />'."\n";
}
add_action('admin_head', 'add_social_admin_header');

/** Add options page **/
function show_social_options_page() {
    include("social-web-links-options.php");
}

function add_social_options_page() {
    add_options_page('Social Web Links Options', 'social-web-links', 8, __FILE__, 'show_social_options_page');
}
add_action('admin_menu', 'add_social_options_page');

/** Adding the settings link **/
function add_social_settings_link($links) {
    $settings_link = '<a href="options-general.php?page=social-web-links/social-web-links.php">' . __('Settings','social-web-links') . '</a>';
    array_unshift( $links, $settings_link );
    return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter( 'plugin_action_links_' . $plugin, 'add_social_settings_link' );

/** Registering widgets **/
register_sidebar_widget('Social Web Links', 'social_web_links_widget');
register_widget_control('Social Web Links', 'social_web_links_widget_control',200,200);

if($social_web_link_options['enable_bookmarks'])
    add_filter('the_content','add_bookmarks_to_content');

add_filter('the_content','add_links_to_content');

/** Making the plugin translation ready **/
$plugin_lang_dir = dirname( __FILE__ )."/languages";
load_plugin_textdomain( 'videogall', null, $plugin_lang_dir );

?>